<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <style>
        .hide {
            display: none;
        }

        .c1 {
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            background: rgba(0, 0, 0, .5);
            z-index: 2;
        }

        .c2 {
            background-color: white;
            position: fixed;
            width: 300px;
            height: 200px;
            top: 50%;
            left: 50%;
            z-index: 3;
            margin-top: -150px;
            margin-left: -150px;
            padding-top: 2%;
            padding-left: 2%;
        }
    </style>
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            安灯发起新增
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">

        <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
            <ul class="aui-list aui-form-list" style="margin-top: 1%;overflow-y: auto; ">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">异常类型</div>

                        <div class="aui-list-item-input">
                            <select id="exceptionType" onchange="selectOtherData()" placeholder="请选择异常类型">
                            </select>
                        </div>
                    </div>
                </li>
                <!-- <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">工作流</div>

                        <div class="aui-list-item-input">
                            <select id="ext02" placeholder="请选择工作流">
                            </select>
                        </div>
                    </div>
                </li> -->
                <!-- <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">物料编码</div>

                        <div class="aui-list-item-input">
                            <input type="text" disabled placeholder="物料编码" id="mrlCode" />
                        </div>
                        <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectMrlName()"></i>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">工序编码</div>

                        <div class="aui-list-item-input">
                            <input type="text" disabled placeholder="工序编码" id="opCode" />

                        </div>
                        <i class="aui-input-addon aui-iconfont aui-icon-right" onclick="goSelectOp()"></i>
                    </div>
                </li> -->
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">异常内容</div>

                        <div class="aui-list-item-input">
                            <select id="exceptionContent" placeholder="请选择异常内容">
                            </select>
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">是否停台</div>

                        <div class="aui-list-item-input">
                            <select id="isStop">
                                <option value="0">否</option>
                                <option value="1">是</option>
                            </select>
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label" style="width: 700px;">是否需要工艺维修人员到现场</div>

                        <div class="aui-list-item-input">
                            <select id="isNeed">
                                <option value="否">否</option>
                                <option value="是">是</option>
                            </select>
                        </div>
                    </div>
                </li>
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">备注</div>

                        <div class="aui-list-item-input">
                            <input type="text" placeholder="备注" id="remark" />
                        </div>
                    </div>
                </li>
            </ul>
            <div style="display: flex;
                         justify-content: space-around;
                         padding-top: 10px;
                         padding-bottom: 10px;">
                <div class="aui-btn aui-btn-info" style="width:30%;margin-top:2%;" onclick="closeWin()">取消
                </div>
                <div class="aui-btn aui-btn-info" style="width:30%;margin-top:2%;" onclick="changeState()">确定
                </div>
            </div>
        </div>
        <div id="shade" class="c1 hide"></div>
        <div id="modal" class="c2 hide">
            <p style="margin-left: 10px;font-size: 0.8rem;font-weight: 500;color: #212121;text-align: center;">
                输入班组长或副班组长账号密码</p>
            <ul class="aui-list aui-form-list" style="margin-top: 4%;">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">账号</div>
                        <div class="aui-list-item-input">
                            <input type="text" style="width: 200px;" id="username" />
                        </div>
                    </div>
                </li>
            </ul>
            <ul class="aui-list aui-form-list" style="margin-top: 4%;">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">密码</div>
                        <div class="aui-list-item-input">
                            <input type="password" style="width: 200px;" id="password" />
                        </div>
                    </div>
                </li>
            </ul>
            <footer class="aui-bar aui-bar-tab" style="position: absolute;">
                <div class="aui-btn aui-btn-info" style="width:30%;margin-left:2%;" onclick="Hide()">取消
                </div>
                <div class="aui-btn aui-btn-info" style="width:30%;margin-left:10%;" onclick="deal()">确定</div>
            </footer>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    var exceptionType = "";
    var exceptionContent = "";
    var isStop = "";
    var isNeed = "";
    var remark = "";
    var lineCode = "";
    var lineName = "";
    //初始化
    apiready = function () {
        lineCode = api.pageParam.lineCode;
        lineName = api.pageParam.lineName;
        //查询异常类型下拉框
        doSearchExceptionType();
    }

    //查询异常类型下拉框
    function doSearchExceptionType() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUtilComboxList";
        var data = {
            values: {
                tablename: "usm_exception_type",
                column_name: "name",
                column_value: "sysid",
                condition: "is_delete=0",
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                    }

                    $api.html($api.byId("exceptionType"), html);
                } else {
                    $api.html($api.byId("exceptionType"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    function selectOtherData() {
        var exceptionTypeId = $("#exceptionType").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getUtilComboxList";
        var data = {
            values: {
                tablename: "usm_exception_content",
                column_name: "name",
                column_value: "sysid",
                condition: "exception_type_gid= '" + exceptionTypeId + "'",
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].value + "'>" + list[i].label + "</option>";
                    }

                    $api.html($api.byId("exceptionContent"), html);
                } else {
                    $api.html($api.byId("exceptionContent"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    function goSelectMrlName() {
        api.openWin({
            name: 'selectMrlAndTuhao',
            url: 'selectMrlAndTuhao.html',
            pageParam: {
                name: "andon_launch_detail",
            }
        });
    }

    //选择工序
    function goSelectOp() {
        api.openWin({
            name: 'usmSelectOp',
            url: 'usmSelectOp.html',
            pageParam: {
                name: "andon_launch_detail",
            }
        });
    }

    //工序选择后回调函数
    function setOp(sysid, code, name) {
        opGid = sysid
        $("#opCode").val(code);
    }

    function setMrl(sysid, code, name, drawing) {
        $("#mrlCode").val(code);
    }

    function changeState() {
        exceptionType = $("#exceptionType").val();
        exceptionContent = $("#exceptionContent").val();
        isStop = $("#isStop").val();
        isNeed = $("#isNeed").val();
        remark = $("#remark").val();
        if (exceptionType == null || exceptionType == "" || exceptionType == undefined) {
            api.toast({
                msg: '异常类型不能为空！',
                duration: 3000
            });
            return;
        }
        if (exceptionContent == null || exceptionContent == "" || exceptionContent == undefined) {
            api.toast({
                msg: '异常内容不能为空！',
                duration: 3000
            });
            return;
        }
        if (isStop == null || isStop == "" || isStop == undefined) {
            api.toast({
                msg: '请选择是否停台！',
                duration: 3000
            });
            return;
        }
        //输入账号密码弹框显示
        Show()
    }

    function Show() {
        document.getElementById('modal').classList.remove('hide');
        document.getElementById('shade').classList.remove('hide');
        document.getElementById('username').value = "";
        document.getElementById('password').value = "";
    }

    function Hide() {
        document.getElementById('modal').classList.add('hide');
        document.getElementById('shade').classList.add('hide');
        document.getElementById('username').value = "";
        document.getElementById('password').value = "";
    }

    //保存按钮
    function deal() {
        //账号
        var username = document.getElementById('username').value;
        //密码
        var password = document.getElementById('password').value;

        if (username == null || username == "" || username == undefined) {
            api.toast({
                msg: '账号不能为空！',
                duration: 3000
            });
            return;
        }
        if (password == null || password == "" || password == undefined) {
            api.toast({
                msg: '密码不能为空！',
                duration: 3000
            });
            return;
        }

        api.showProgress({
            title: '保存中...',
        });
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        // var url = serverUrl + "/app/qcmChkRecordSave";
        var url = serverUrl + "/app/CheckShiftUserAndPassNew";
        var data = {
            values: {
                _u: username,
                _p: password,
                un: un,
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 'S') {
                    Hide();
                    submit()
                } else {
                    api.hideProgress();
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                    // Hide();
                }
            } else {
                api.hideProgress();
            }
        });
    }

    function submit() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyAndonCallNew";
        var data = {
            values: {
                exceptionType: exceptionType,
                exceptionContent: exceptionContent,
                isStop: isStop,
                remark: remark,
                isNeed: isNeed,
                lineCode: lineCode,
                lineName: lineName,
                un: un,
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功!",
                        duration: 3000
                    });
                    cancle();
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    //取消按钮
    function cancle() {
        api.closeWin({});
        api.execScript({
            name: 'andon_launch',
            script: 'refresh()'
        });
    }

    //订单返回按钮
    function closeWin() {
        api.closeWin({});
    }
</script>

</html>